home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Src / Var / spc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-06  |  7.6 KB  |  312 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     $Id: spc.c 1.1 1994/09/20 11:14:01 b_noll Exp b_noll $
  5.  
  6.     DESCRIPTION
  7.     That module represents ab interface to all
  8.     variables, which have a special meaning for
  9.     XDME's behaviour; strictl speaking the current
  10.     file is the interface part, while the implementation
  11.     of the access functions is done via a automatically
  12.     generated file (called _SPC_.c), which is created
  13.     from a file in a meta language (SPC.pre)
  14.  
  15.     NOTES
  16.  
  17.     $Log: spc.c $
  18.  * Revision 1.1  1994/09/20  11:14:01  b_noll
  19.  * Initial revision
  20.  *
  21.  
  22.  
  23. ******************************************************************************/
  24.  
  25. /**************************************
  26.         Includes
  27. **************************************/
  28.  
  29. #include "defs.h"
  30. //#include "null.h"
  31.  
  32.  
  33. /**************************************
  34.         Globale Variable
  35. **************************************/
  36.  
  37.  
  38.  
  39. /**************************************
  40.       Interne Defines & Strukturen
  41. **************************************/
  42.  
  43. static int   spc_set (long, char *);
  44. static char *spc_get (long);
  45.  
  46. /**************************************
  47.         Interne Variable
  48. **************************************/
  49.  
  50. struct genflags genflags;
  51.  
  52. /**************************************
  53.        Interne Prototypes
  54. **************************************/
  55.  
  56. // extern int VSTK_Internal;
  57. extern UBYTE Fstr[];
  58. extern UBYTE Rstr[];
  59.  
  60.  
  61.  
  62. #include "gen_spc.h"
  63.  
  64.  
  65. Prototype UBYTE *ltostr (long l);
  66. UBYTE *ltostr (long l) {
  67.     static UBYTE buffer[16];
  68.     sprintf (buffer, "%ld", l);
  69.     return buffer;
  70. }
  71.  
  72. Prototype char *strrep (char *old, const char *new);
  73. char * strrep (char *old, const char *new) {
  74.     char *dup;
  75.     if (dup = strdup(new)) {
  76.     free (old);
  77.     return dup;
  78.     } else {
  79.     nomemory();
  80.     return old;
  81.     } /* if */
  82. } /* strrep */
  83.  
  84.  
  85. #if 0
  86. // the advantage of that function is, we can reuse it for any kind of
  87. // tables ...
  88. static
  89. unsigned long Bin_access(const void *array, long E_size, long A_size, const char *find) {
  90.     long high, low, mid;
  91.     int  diff;
  92.     const char **cptr;
  93.  
  94.     high = A_size -1;
  95.     low  = 0;
  96.  
  97.     do {
  98.     mid  = (high + low) >> 1;
  99.     cptr = (void *)(mid * E_size + (unsigned long) array);
  100.     diff = strcmp (*cptr, find);
  101.     if (diff > 0)
  102.         high = mid;
  103.     else if (diff)
  104.         high = mid;
  105.     else
  106.         return (unsigned long)mid;
  107.     } while (low <= high);
  108.  
  109.     return (unsigned long)~0;
  110. } /* Bin_access */
  111. #else
  112. static
  113. unsigned long Bin_access(const char **array, long NUPE, long A_size, const char *find) {
  114.     long low, high, mid;
  115.     int  diff;
  116.  
  117.     high = A_size -1;
  118.     low  = 0;
  119.  
  120.     do {
  121.     mid  = (low + high) >> 1;
  122.     diff = stricmp (find, array[mid]);
  123.     if (diff < 0)
  124.         high = mid-1;
  125.     else if (diff)
  126.         low  = mid+1;
  127.     else
  128.         return (unsigned long)mid;
  129.     } while (low <= high);
  130.  
  131.     return (unsigned long)~0;
  132. } /* Bin_access */
  133. #endif
  134.  
  135.  
  136. DEFVARTREE( 20, "SPC_", VAR_SV, 4, 4, 0, NULL, NULL, SPC_set, SPC_get )
  137.  
  138. static long spc_lock(const char *name) {
  139.     if (!name)
  140.     return 0;
  141.     return ~(long)Bin_access (spc_names,
  142.                   sizeof (char *),
  143.                   spc_num_vars,
  144.                   name);
  145. }
  146.  
  147. Prototype char SPC_set (const char *name, const char *value);
  148. char SPC_set (const char *name, const char *value) {
  149.     long lock;
  150.     if ((lock = spc_lock(name))) {
  151.     if (!spc_set(~lock, value))
  152.         SET_ABORTION( 1 );
  153.     return 1;
  154.     } /* if */
  155.     return 0;
  156. } /* spc_set */
  157.  
  158.  
  159. Prototype char *SPC_get (const char *name);
  160. char *SPC_get (const char *name) {
  161.     long lock;
  162.     if ((lock = spc_lock(name))) {
  163.     char * str;
  164.     if (!(str = spc_get(~lock))) {
  165.         SET_ABORTION( 1 );
  166.         return NULL;
  167.     } /* if */
  168.     if (str = strdup(str))
  169.         return str;
  170.     nomemory();
  171.     } /* if */
  172.     return NULL;
  173. } /* spc_get */
  174.  
  175. int SPC_setloud (const char *name, const char *value)
  176. {
  177.     long lock;
  178.     if ((lock = spc_lock(name))) {
  179.     if (!spc_set(~lock, value))
  180.         SET_ABORTION( 1 );
  181.     spc_say(~lock);
  182.     return 1;
  183.     } /* if */
  184.     return 0;
  185. } /* SPC_say */
  186.  
  187.  
  188.  
  189.  
  190. /*************************************************
  191.     This function is to be called for all
  192.     setting any special var via a command:
  193.     SPC varname value
  194.    The only thing is - the variable must be
  195.    treated here
  196. *************************************************/
  197. /*DEFLONG #long SPC
  198.  
  199. This command allows access to almost every XDME internal
  200. variable, that is, it can replace almost every preferences
  201. command; additionally to the funcionality of the current
  202. prefs commands, it cn access some System Variables, which
  203. themselfes have no preferences commands, like the
  204. AppIcon variables, the CmdShell Variables and some more
  205. this is a list of the variables that should be settable
  206. w/ @{B}SPC@{UB}.
  207.  
  208. activetofront,        appicon,        appiconclickaction,
  209. appicondropaction,  appiconname,    appicontitle,
  210. autoindent,        autosplit,        autounblock,
  211. bbpen,            bgpen,        block,
  212. cmdshell,        cmdshellname,    cmdshellprompt,
  213. currentdir,        debug,        dobackup,
  214. ed,            errorsoncmdshell,    fgpen,
  215. filename,        findstr,        followcursor,
  216. globalsearch,        gtbformat,        hgpen,
  217. icon,            iconactive,     iconmode,
  218. icontitle,        ignorecase,     infixmode,
  219. insertmode,        keytable,        margin,
  220. menufontname,        menufontsize,    menustrip,
  221. modified,        nicepaging,     norequest,
  222. parcol,         pens,        pos,
  223. repstr,         reqpattern,     reqresult,
  224. rexxport,        rxresult,        saveicons,
  225. savetabs,        scanf,        shortlines,
  226. showtitle,        simpletabs,     sourcebreaks,
  227. tabstop,        tbpen,        tfpen,
  228. viewmode,        warningsoncmdshell, window,
  229. windowcycling,        windowtitles,    wordwrap
  230.  
  231.  
  232. Please note, that each variable settable w/ SPC is also usable in
  233. the Varstack; however the ED, POS and BLOCK should be used w/ care.
  234.  
  235. for the completeness: the following vars cannot be changed w/ SPC
  236. ascii,            colno,        comlinemode,
  237. currentline,        currentword,    firstnb,
  238. itemcheck,        lineno,        numlines,
  239. prevnbline,        recentword,     reqresult,
  240. restofline,        rexxport,        txtfontname,
  241. txtfontsize,        version
  242. */
  243.  
  244. /*DEFHELP #cmd var SPC var value - Modify an internal XDME system variable */
  245. DEFUSERCMD("spc", 2, CF_VWM|CF_COK|CF_ICO, void, do_setspecialvar, (void),)
  246. {
  247.     if (!SPC_setloud(av[1],av[2]))
  248. DEFMESSAGE(_VAR_cant_set_sysvar_2, "%s:\nCannot set system variable `%s'\nto `%s'")
  249.     error (_VAR_cant_set_sysvar_2, av[0], av[1], av[2]);
  250. } /* do_setspecialvar */
  251.  
  252.  
  253. /*************************************************
  254.     We could use that function in order to
  255.     emulate any of the functions in prefs.c,
  256.     which has a here settable variable
  257.     (as long, as the variable)/set is not a
  258.     frontend for the prefs function
  259.     like e.g. $path)
  260. *************************************************/
  261. /* Prototype void do_specialvar (void);
  262. void do_specialvar (void)
  263. {
  264.     if (!SPC_setloud(av[0],av[1]))
  265.     SET_ABORTION(1);
  266. } /* do_setspecialvar */
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275. /***************************************************
  276.      test driver for Lock function
  277. ***************************************************/
  278.  
  279. #ifdef TEST
  280.  
  281. /*
  282. struct __XDMEArgs XDMEArgs;
  283. UWORD Mx, My;
  284. char MShowTitle, noadj;
  285. struct MsgPort *Sharedport;
  286. */
  287.  
  288. UBYTE tmp_buffer[256];
  289.  
  290. int main(int ac, char ** av) {
  291.     int i;
  292.     for (i = 0; i < spc_num_vars; ++i) {
  293.     printf ("accessing %d/%s -> %d\n", i, spc_names[i], spc_lock(spc_names[i]));
  294.     } /* for */
  295.  
  296.     printf ("accessing %d/%s -> %d\n", i, "hallo", spc_lock("hallo"));
  297.     printf ("accessing %d/%s -> %d\n", i, "_oops", spc_lock("_oops"));
  298.     printf ("accessing %d/%s -> %d\n", i, "Aetsch", spc_lock("Aetsch"));
  299.     printf ("accessing %d/%s -> %d\n", i, "}{", spc_lock("}{"));
  300.     printf ("accessing %d/%s -> %d\n", i, "00", spc_lock("00"));
  301.     printf ("accessing %d/%s -> %d\n", i, "", spc_lock(""));
  302.  
  303.     return 0;
  304. }
  305.  
  306. #endif
  307.  
  308. /******************************************************************************
  309. *****  ENDE spc.c
  310. ******************************************************************************/
  311.  
  312.